<?php
class controller_Index extends ACL
{
    protected $layout;
    protected $model;
    protected $modelUser;

    function __construct()
    {
        $this->layout = new _View('layout/index.phtml');
        $this->model = new model_Article;
        $this->modelUser = new model_User;
        $this->layout->user = $this->modelUser->getCurrentUser();
    }

    function login()
    {
        if (isset($_POST['login']) && isset($_POST['password']))
        {
            $user = $this->modelUser->login($_POST);
            if (isset($user[0])) return $this->index();
        }
        $this->layout->main = new _View('login.phtml');
        return $this->layout;
    }

    function logout()
    {
        $this->modelUser->logout();
        return $this->index();
    }

    // ...reszta tak jak wczesniej
        function index()
    {
        $view = new _View('index.phtml');
        $view->data = $this->model->getItems();
        $this->layout->main = $view;
        return $this->layout;
    }

    function article()
    {
        if (empty($_GET['id'])) self::http404();
        $data = $this->model->getItem(array('id' => $_GET['id']));
        if (empty($data[0])) self::http404();
        self::$config['title'][] = $data[0]->title;
        $view = new _View('article.phtml');
        $view->data = $data;
        $this->layout->main = $view;
        return $this->layout;
    }
}
?>

